// Technische Universitaet Muenchen 
// Fakultaet fuer Informatik 
//
// Praktikum des Uebersetzerbaus
//
// Main.java
//
// Main program for Mima Compiler
// consisting of Lexer, Parser and Visitors
// (generated with JFlex, CUP and classgen)
//  
// JFlex - The Fast Scanner Generator for Java
// home page: 
// http://www.jflex.de/  
//
// CUP - LALR Parser Generator for Java
// home page: 
// http://www2.in.tum.de/projects/cup
//
//  Classgen Class Generator for Java
//  home page:
//  http://classgen.sf.net


import java.io.*;

import java_cup.runtime.Symbol;

public class Main {

	/**
	 * set to true if you want to study the parsing process
	 */

  static boolean do_debug_parse = false;
	
	String[] my_args;
	public static void main(String[] args) {
		System.out.println("parsing [" + args[0] + "]");
		
		try {
		   FileReader fr = new FileReader(new File(args[0]));
		   Lexer mylexer = new Lexer(fr);
		
			Parser my_parser = new Parser(mylexer, args[0]);

			Symbol top;
	 
	      try {
	        if (do_debug_parse)
	          top = my_parser.debug_parse();
	        else
	          top = my_parser.parse();
	                
	        //Stop if parsing failed
	        if (my_parser.hasFailed()) return ;
	        
	        System.out.println("Parsing Completed. Top symbol = " + top.toString());
	        
	      } catch(Error e) {
	    	  	System.out.println("error(1) was:" + e.toString());
	      } catch (Exception e) {
	         //do cleanup here -- possibly rethrow e 
	    	  	System.out.println("error(2) was:" + e.toString());
	      } finally {
		     //do close out here 
	      }
	} catch (FileNotFoundException e) {
	    e.printStackTrace();
	}
	}
}




